package logger

import (
	"context"
	"io"
)

type Option func(*Options)

type Options struct {
	Level           Level
	Fields          map[string]any
	Out             io.Writer
	CallerSkipCount int
	Context         context.Context
	Name            string
}

func WithFields(fields map[string]any) Option {
	return func(options *Options) {
		options.Fields = fields
	}
}

func WithLevel(level Level) Option {
	return func(options *Options) {
		options.Level = level
	}
}

func WithOutput(out io.Writer) Option {
	return func(options *Options) {
		options.Out = out
	}
}

func WithCallerSkipCount(c int) Option {
	return func(options *Options) {
		options.CallerSkipCount = c
	}
}

func WithName(name string) Option {
	return func(options *Options) {
		options.Name = name
	}
}

func SetOption(k, v any) Option {
	return func(options *Options) {
		if options.Context == nil {
			options.Context = context.Background()
		}
		options.Context = context.WithValue(options.Context, k, v)
	}
}
